﻿using System;
using System.Drawing;
using System.Windows.Forms;
using DarkAngels.WoW.Library.Armory;
using DarkAngels.WoW.Library.Armory.Character;
using DarkAngels.WoW.Library.Armory.Character.tabs;
using DarkAngels.WoW.Library.Armory.Guild;
using DarkAngels.WoW.Library.Network;

namespace SmartDeviceProject1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.FormBorderStyle = FormBorderStyle.None;
            this.WindowState = FormWindowState.Maximized;
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            Close();
        }

        /// <summary>
        /// Basic data test - working 2010.01.04
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItem6_Click(object sender, EventArgs e)
        {
            try
            {
                textBox1.Visible = true;
                Cursor.Current = Cursors.WaitCursor;
                //fetch some test data ...
                Character char1 = new Character("nemu", "Twilight's Hammer", ArmoryRegion.EU);
                char1.Provider = new SimpleNetworking(); //not mandatory/needed, but used to show how it can be done
                CharacterTab charTab = char1.CharacterInfo;
                textBox1.Text = String.Format("Class: {2}, Faction: {0}, Gender: {1}", char1.Faction, char1.Gender, char1.Class);
                Cursor.Current = Cursors.Default;
            }
            catch (Exception exc)
            {
                textBox1.Text = exc.Message + "\n\n" + exc.StackTrace;
                Cursor.Current = Cursors.Default;
            }
        }

        /// <summary>
        /// Guild test 1 - working 2010.01.05
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItem5_Click(object sender, EventArgs e)
        {
            try
            {
                textBox1.Visible = true;
                Cursor.Current = Cursors.WaitCursor;
                //fetch some test data ...
                Guild guild = new Guild("Dark Angels", "Twilight's Hammer", ArmoryRegion.EU);
                guild.Load();
                textBox1.Text = String.Format("Member count: {0}, Name of the 10th member: {1}", guild.MemberCount, guild.Members[9].CharacterName);
                Cursor.Current = Cursors.Default;
            }
            catch (Exception exc)
            {
                textBox1.Text = exc.Message + "\n\n" + exc.StackTrace;
                Cursor.Current = Cursors.Default;
            }
        }

        /// <summary>
        /// Avatar test - working 2010.01.04
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItem7_Click(object sender, EventArgs e)
        {
            try
            {
                textBox1.Visible = false;
                Cursor.Current = Cursors.WaitCursor;
                Character char1 = new Character("nemu", "Twilight's Hammer", ArmoryRegion.EU);
                char1.Load();
                pictureBox1.Image = char1.Avatar;
                Cursor.Current = Cursors.Default;
            }
            catch (Exception exc) {
                textBox1.Visible = true;
                textBox1.Text = exc.Message + "\n\n" + exc.StackTrace;
                Cursor.Current = Cursors.Default;
            }
        }

        /// <summary>
        /// Other tests 1 - working 2010.01.04
        /// (Basically just a copy of the avatar test atm but used for making new tests)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItem9_Click(object sender, EventArgs e)
        {
            try
            {
                textBox1.Visible = false;
                Cursor.Current = Cursors.WaitCursor;
                SimpleNetworking smp = new SimpleNetworking();
                smp._OpenConnection();
                System.Net.WebRequest request = System.Net.WebRequest.Create("http://eu.wowarmory.com/images/portraits/wow-80/1-1-8.gif");
                System.Net.WebResponse response = request.GetResponse();
                System.IO.Stream responseStream = response.GetResponseStream();
                Bitmap bitmap2 = new Bitmap(responseStream);
                pictureBox1.Image = bitmap2;
                Cursor.Current = Cursors.Default;
                smp._CloseConnection();
            }
            catch (System.Net.WebException)
            {
                MessageBox.Show("There was an error opening the image file."
                   + "Check the URL");
            }
        }

        /// <summary>
        /// Reputation test - working 2010.01.04
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItem10_Click(object sender, EventArgs e)
        {
            try
            {
                textBox1.Visible = true;
                Cursor.Current = Cursors.WaitCursor;
                //fetch some test data ...
                Character char1 = new Character("nemu", "Twilight's Hammer", ArmoryRegion.EU);
                ReputationTab tab1 = char1.ReputationInfo;
                textBox1.Text = String.Format("Reputation Categories found: {0}, 1st category contains {1} factions, the 1st of which is {2} ({3})", tab1.Factions.Count, tab1.Factions[0].Factions.Length, tab1.Factions[0].Factions[0].Name, tab1.Factions[0].Factions[0].ReputationLevel);
                textBox1.Text += String.Format("{0}We also found a total of {1} factions, of which {2} are considered headers.", Environment.NewLine, tab1.NumberOfFactions, tab1.Factions.Count);
                Cursor.Current = Cursors.Default;
            }
            catch (Exception exc)
            {
                textBox1.Text = exc.Message + "\n\n" + exc.StackTrace;
                Cursor.Current = Cursors.Default;
            }
        }

        /// <summary>
        /// Realm test 1 - working 2010.01.04
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItem12_Click(object sender, EventArgs e)
        {
            try
            {
                textBox1.Visible = true;
                Cursor.Current = Cursors.WaitCursor;
                //fetch some test data ...
                DarkAngels.WoW.Library.Armory.Realm.RealmStatus list = new DarkAngels.WoW.Library.Armory.Realm.RealmStatus(ArmoryRegion.EU, new SimpleNetworking());
                list.Load();
                textBox1.Text = String.Format("First realm's name: {0}", list.Realms[0].Name);
                Cursor.Current = Cursors.Default;
            }
            catch (Exception exc)
            {
                textBox1.Text = exc.Message + "\n\n" + exc.StackTrace;
                Cursor.Current = Cursors.Default;
            }
        }

        /// <summary>
        /// Spell stats test - working 2010.01.04
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItem13_Click(object sender, EventArgs e)
        {
            //test spell stats
            try
            {
                textBox1.Visible = true;
                Cursor.Current = Cursors.WaitCursor;
                //fetch some test data ...
                Character char1 = new Character("nemu", "Twilight's Hammer", ArmoryRegion.EU);
                char1.Provider = new SimpleNetworking(); //not mandatory/needed, but used to show how it can be done
                CharacterTab charTab = char1.CharacterInfo;
                textBox1.Text = String.Format("Healing Bonus: {0}, Fire Bonus: {1}, Fire Crit: {2}, Overall Hit Rating: {3}", charTab.HealingBonus, charTab.FireBonus, charTab.FireCritChance, charTab.SpellHitIncrease);
                Cursor.Current = Cursors.Default;
            }
            catch (Exception exc)
            {
                textBox1.Text = exc.Message + "\n\n" + exc.StackTrace;
                Cursor.Current = Cursors.Default;
            }
        }

        /// <summary>
        /// Achievements test 1 - workin 2010.01.04
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItem15_Click(object sender, EventArgs e)
        {
            try
            {
                textBox1.Visible = true;
                Cursor.Current = Cursors.WaitCursor;
                //fetch some test data ...
                Character char1 = new Character("nemu", "Twilight's Hammer", ArmoryRegion.EU);
                AchievementTab achiv = char1.AchievementsInfo;
                textBox1.Text = String.Format("Achievements earned: {0}, Points earned: {1}, Number of achievements: {2}, First category name: {3}", achiv.AchievementsEarned, achiv.PointsEarned, achiv.AchievementsTotal, achiv.Categories[0].Name);
                Cursor.Current = Cursors.Default;
            }
            catch (Exception exc)
            {
                textBox1.Text = exc.Message + "\n\n" + exc.StackTrace;
                Cursor.Current = Cursors.Default;
            }
        }

        /// <summary>
        /// Profession test 1 - working 2010.01.07
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItem16_Click(object sender, EventArgs e)
        {
            try
            {
                textBox1.Visible = true;
                Cursor.Current = Cursors.WaitCursor;
                //fetch some test data ...
                Character char1 = new Character("nemu", "Twilight's Hammer", ArmoryRegion.EU);
                CharacterTab c_tab = char1.CharacterInfo;
                Character char2 = new Character("teletha", "Twilight's Hammer", ArmoryRegion.EU);
                CharacterTab c_tab2 = char2.CharacterInfo;
                textBox1.Text = String.Format("{0}'s 2 professions are: {1} ({3} / {4}) and {2} ({5} / {6})", char1.CharacterName, c_tab.Profession1.Name, c_tab.Profession2.Name, c_tab.Profession1.Current, c_tab.Profession1.Max, c_tab.Profession2.Current, c_tab.Profession2.Max);
                textBox1.Text += String.Format("\n\n\n{0}'s 2 professions are: {1} ({3} / {4}) and {2} ({5} / {6})", char2.CharacterName, c_tab2.Profession1.Name, c_tab2.Profession2.Name, c_tab2.Profession1.Current, c_tab2.Profession1.Max, c_tab2.Profession2.Current, c_tab2.Profession2.Max);
                Cursor.Current = Cursors.Default;
            }
            catch(Exception exc)
            {
                textBox1.Text = exc.Message + "\n\n" + exc.StackTrace;
                Cursor.Current = Cursors.Default;
            }
        }

        /// <summary>
        /// Base Stats test 1
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItem17_Click(object sender, EventArgs e)
        {
            try
            {
                textBox1.Visible = true;
                Cursor.Current = Cursors.WaitCursor;
                //fetch some test data ...
                Character char1 = new Character("nemu", "Twilight's Hammer", ArmoryRegion.EU);
                CharacterTab c_tab = char1.CharacterInfo;
                Character char2 = new Character("kayama", "Twilight's Hammer", ArmoryRegion.EU);
                CharacterTab c_tab2 = char2.CharacterInfo;
                textBox1.Text = String.Format("{0}...", char1.CharacterName, c_tab.BaseAgility);
                textBox1.Text += String.Format("\n\n\n{0} has: {1} base armor and {2} base agility", char2.CharacterName, c_tab2.BaseArmor, c_tab2.BaseAgility);
                Cursor.Current = Cursors.Default;
            }
            catch (Exception exc)
            {
                textBox1.Text = exc.Message + "\n\n" + exc.StackTrace;
                Cursor.Current = Cursors.Default;
            }
        }
    }
}